package com.chuangke.common.express;

import java.util.ArrayList;
import java.util.List;

/**
 * 表达式变量数
 * 
 * @author sutongming
 *
 */
public class CkExpression {

	private String referVar;// 指向的引用变量
	private String expression;// 表达式
	private final List<CkExpression> factorVars;// 因子变量
	private int level ;//树形表达式的深度
	
	public CkExpression(String referVar, String expression) {
		this.referVar = referVar;
		this.expression = expression;
		factorVars = new ArrayList<>() ;
		level = 1 ;
	}

	public String getExpression() {
		return expression;
	}

	public void setExpression(String expression) {
		this.expression = expression;
	}

	public String getReferVar() {
		return referVar;
	}

	public void setReferVar(String referVar) {
		this.referVar = referVar;
	}

	public List<CkExpression> getFactorVars() {
		return factorVars;
	}

	public void addFactorVar(CkExpression factor) {
		factorVars.add(factor) ;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	@Override
	public int hashCode() {
		return referVar.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
            return true;
        }
		
		return referVar.equals(((CkExpression)obj).referVar);
	}

	@Override
	public String toString() {
		return referVar+"="+expression;
	}

}
